﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using PloobsEngine.IA;
using PloobsEngine;
using PloobsEngine.SceneControl;

namespace Etapa1.Pedestrian
{
    public class MovingCharacter : IScreenUpdateable
    {
        Curve cx = new Curve();
        Curve cy = new Curve();
        Curve cz = new Curve();
        IObject obj;

        public MovingCharacter(IScreen sc, LinkedList<Waypoint> ways,IObject obj) 
            : base(sc)
        {

            this.obj = obj;
            float time = 0;
            foreach (var item in ways)
            {
                cx.Keys.Add(new CurveKey(time, item.WorldPos.X));
                cy.Keys.Add(new CurveKey(time, item.WorldPos.Y));
                cz.Keys.Add(new CurveKey(time, item.WorldPos.Z));
                time += 300;
            }

            cx.ComputeTangents(CurveTangent.Smooth);
            cy.ComputeTangents(CurveTangent.Smooth);
            cz.ComputeTangents(CurveTangent.Smooth);

            this.Start();
        }

        int t = 0;
        public override void Update(GameTime gameTime)
        {
            t++;
            obj.Position = new Vector3(cx.Evaluate(t), cy.Evaluate(t), cz.Evaluate(t));
        }

    }
}
